home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / INPTPRSL.H < prev    next >
C/C++ Source or Header  |  1992-01-28  |  10KB  |  317 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. *   General, local to module, definitions for the Input Parser module.         *
  7. *   Note this module actually consists of InptPrsr/InptEval/OverLoad modules.*
  8. *****************************************************************************/
  9.  
  10. #ifndef    INPT_PRSR_LH
  11. #define    INPT_PRSR_LH
  12.  
  13. /* #define DEBUG        Print some intermediate results (InptPrsr/InptEval). */
  14.  
  15. #define MAX_PARSER_STACK    200         /* Depth of expression nesting. */
  16.  
  17. typedef enum {
  18.     POLY_EXPR =     0x0001,
  19.     NUMERIC_EXPR =  0x0002,
  20.     VECTOR_EXPR    =   0x0004,
  21.     MATRIX_EXPR    =   0x0008,
  22.     CURVE_EXPR =    0x0010,
  23.     SURFACE_EXPR =  0x0020,
  24.     STRING_EXPR    =   0x0040,
  25.     OLST_EXPR =     0x0080,
  26.     CTLPT_EXPR =    0x0100,
  27.  
  28.     NO_EXPR =       0x1000,
  29.     POLY_CURVE_EXPR = POLY_EXPR | CURVE_EXPR,
  30.     GEOM_EXPR =     POLY_EXPR | CURVE_EXPR | SURFACE_EXPR,
  31.     OLST_GEOM_EXPR = OLST_EXPR | GEOM_EXPR,
  32.     ANY_EXPR =      POLY_EXPR | NUMERIC_EXPR | VECTOR_EXPR |
  33.                 MATRIX_EXPR | CURVE_EXPR | SURFACE_EXPR |
  34.             STRING_EXPR | OLST_EXPR | CTLPT_EXPR,
  35.  
  36.     ERROR_EXPR =    0x4000
  37. } IritExprType;
  38.  
  39.  
  40. extern InptPrsrEvalErrType IPGlblEvalError;     /* Global used by EvalTree. */
  41.  
  42. /*****************************************************************************
  43. * The expression parse tree node definition:                     *
  44. *****************************************************************************/
  45. typedef    struct ParseTree {
  46.     struct ParseTree *Right, *Left;
  47.     int NodeKind;
  48.     IritObjectType ObjType;
  49.     union {
  50.     RealType R;
  51.     ObjectStruct *PObj;
  52.     } U;
  53. } ParseTree;
  54.  
  55. /* See Irit.h file for the different object possible: */
  56. #define IS_POLY_NODE(Node)    ((Node)->ObjType == POLY_OBJ)
  57. #define IS_NUM_NODE(Node)    ((Node)->ObjType == NUMERIC_OBJ)
  58. #define IS_VEC_NODE(Node)    ((Node)->ObjType == VECTOR_OBJ)
  59. #define IS_CTLPT_NODE(Node)    ((Node)->ObjType == CTLPT_OBJ)
  60. #define IS_MAT_NODE(Node)    ((Node)->ObjType == MATRIX_OBJ)
  61. #define IS_STR_NODE(Node)    ((Node)->ObjType == STRING_OBJ)
  62. #define IS_OLST_NODE(Node)    ((Node)->ObjType == OBJ_LIST_OBJ)
  63. #define IS_CRV_NODE(Node)    ((Node)->ObjType == CURVE_OBJ)
  64. #define IS_SRF_NODE(Node)    ((Node)->ObjType == SURFACE_OBJ)
  65.  
  66. /*****************************************************************************
  67. * The include file stack - nesting is allowed up to FILE_STACK_SIZE.         *
  68. *****************************************************************************/
  69. typedef struct FileStackStruct {
  70.     char Name[FILE_NAME_LEN];
  71.     FILE *f;
  72. } FileStackStruct;
  73.  
  74. #define FILE_STACK_SIZE    10
  75.  
  76. /*****************************************************************************
  77. * Aliases are simple strings substitution - each entry holds alias Name and  *
  78. * alias Value, which replaces Name. Name id not NULL if active.             *
  79. *****************************************************************************/
  80. typedef struct OneAliasStruct {
  81.     char *Name, *Value;
  82. } OneAliasStruct;
  83.  
  84. #define NUM_OF_ALIASES    10
  85.  
  86. typedef struct AliasesStruct {
  87.     OneAliasStruct Aliases[NUM_OF_ALIASES];
  88. } AliasesStruct;
  89.  
  90. /*****************************************************************************
  91. * Function entry table looks like this (for table see InptPrsr.c module):    *
  92. *****************************************************************************/
  93. #define FUNC_NAME_LEN    11                /* 10 + NULL terminator. */
  94. #define FUNC_MAX_PARAM    4        /* Max. of all the function types below. */
  95. #define ANY_PARAM_NUM    127
  96.  
  97. typedef struct FuncTableType {
  98.     char FuncName[FUNC_NAME_LEN];
  99.     int FuncToken;
  100.     void (*Func)();
  101.     ByteType NumOfParam;
  102.     IritExprType ParamObjType[FUNC_MAX_PARAM];
  103. } FuncTableType;
  104.  
  105. typedef struct NumFuncTableType {
  106.     char FuncName[FUNC_NAME_LEN];
  107.     int FuncToken;
  108. #ifdef __MSDOS__
  109.     double cdecl (*Func)(); /* So we can use -pr option of Borland C++ 3.0. */
  110. #else
  111.     double (*Func)();
  112. #endif /* __MSDOS__ */
  113.     ByteType NumOfParam;
  114.     IritExprType ParamObjType[FUNC_MAX_PARAM];
  115. } NumFuncTableType;
  116.  
  117. typedef struct ObjFuncTableType {
  118.     char FuncName[FUNC_NAME_LEN];
  119.     int FuncToken;
  120.     ObjectStruct *(*Func)();
  121.     ByteType NumOfParam;
  122.     IritExprType ParamObjType[FUNC_MAX_PARAM];
  123. } ObjFuncTableType;
  124.  
  125. typedef struct GenFuncTableType {
  126.     char FuncName[FUNC_NAME_LEN];
  127.     int FuncToken;
  128.     void (*Func)();
  129.     ByteType NumOfParam;
  130.     IritExprType ParamObjType[FUNC_MAX_PARAM];
  131. } GenFuncTableType;
  132.  
  133. typedef struct ConstantTableType {
  134.     char FuncName[FUNC_NAME_LEN];
  135.     RealType Value;
  136. } ConstantTableType;
  137.  
  138. /* The followings are defined in the InptEval.c module and are globals so   */
  139. /* InptPrsr.c module will be able to access them...                */
  140. extern NumFuncTableType NumFuncTable[];
  141. extern int NumFuncTableSize;
  142. extern ObjFuncTableType ObjFuncTable[];
  143. extern int ObjFuncTableSize;
  144. extern GenFuncTableType GenFuncTable[];
  145. extern int GenFuncTableSize;
  146. extern ConstantTableType ConstantTable[];
  147. extern int ConstantTableSize;
  148.  
  149. /*****************************************************************************
  150. * Tokens used in the expression    to tree    conversion and tree definition.         *
  151. *****************************************************************************/
  152.  
  153. #define    TOKENERROR  0
  154.  
  155. /* Warning - changing the order of these constants, needs updating the order */
  156. /* of them, in the tables in the begining of InptPrsr.c & OverLoad.c modules.*/
  157.  
  158. #define    ARCCOS        100               /* Real value returned functions. */
  159. #define    ARCSIN        101
  160. #define    ARCTAN2        102
  161. #define    ARCTAN        103
  162. #define    COS        104
  163. #define    EXP        105
  164. #define    FABS        106
  165. #define    LN        107
  166. #define    LOG        108
  167. #define    SIN        109
  168. #define    SQRT        110
  169. #define    TAN        111
  170. #define CPOLY        112
  171. #define AREA        113
  172. #define VOLUME      114
  173. #define TIME        115
  174.  
  175. #define NUM_FUNC    100
  176. #define NUM_FUNC_OFFSET    100
  177. #define IS_NUM_FUNCTION(Token)        (Token >= 100 && Token < 200)
  178.  
  179. #define VECTOR        200                   /* Object returned Functions. */
  180. #define CTLPT        201
  181. #define ROTX        202
  182. #define ROTY        203
  183. #define ROTZ        204
  184. #define TRANS        205
  185. #define SCALE        206
  186. #define BOX        207
  187. #define GBOX        208
  188. #define CONE        209
  189. #define CONE2        210
  190. #define CYLIN        211
  191. #define SPHERE        212
  192. #define TORUS        213
  193. #define CIRCPOLY    214
  194. #define POLY        215
  195. #define CROSSEC        216
  196. #define SURFREV     217
  197. #define EXTRUDE     218
  198. #define LIST        219
  199. #define LOAD        220
  200. #define CONVEX        221
  201. #define SBEZIER     222
  202. #define CBEZIER     223
  203. #define SBSPLINE    224
  204. #define CBSPLINE    225
  205. #define SEVAL       226
  206. #define CEVAL       227
  207. #define STANGENT    228
  208. #define CTANGENT    229
  209. #define SNORMAL     230
  210. #define SDIVIDE        231
  211. #define CDIVIDE     232
  212. #define SREGION        233
  213. #define CREGION     234
  214. #define SREFINE     235
  215. #define CREFINE     236
  216. #define SRAISE      237
  217. #define CRAISE      238
  218. #define CSURFACE    239
  219. #define CMESH       240
  220. #define NTH         241
  221. #define GPOLYGON    242
  222. #define GPOLYLINE   243
  223. #define CIRCLE      244
  224. #define ARC         245
  225. #define RULEDSRF    246
  226. #define BOOLSUM     247
  227. #define SFROMCRVS   248
  228. #define SWEEPSRF    249
  229. #define OFFSET      250
  230. #define CEDITPT     251
  231. #define SEDITPT     252
  232. #define MERGEPOLY   253
  233.  
  234. #define OBJ_FUNC    200
  235. #define OBJ_FUNC_OFFSET    200
  236. #define IS_OBJ_FUNCTION(Token)        (Token >= 200 && Token < 300)
  237.  
  238. #define EXIT        300       /* General Functions/No value returned functions. */
  239. #define VIEW        301
  240. #define DIR        302
  241. #define CHDIR        303
  242. #define NORMAL        304
  243. #define INCLUDE        305
  244. #define SAVE        306
  245. #define FREEOBJ     307
  246. #define INTERACT    308
  247. #define PAUSE        309
  248. #define IFCOND        310
  249. #define FORLOOP        311
  250. #define PRHELP        312
  251. #define VARLIST        313
  252. #define ALIAS        314
  253. #define BEEP        315
  254. #define EDIT        316
  255. #define SYSTEM        317
  256. #define LOGFILE        318
  257. #define COLOR        319
  258. #define SNOC        320
  259. #define ATTRIB        321
  260. #define CLOSED        322
  261.  
  262. #define COMMENT        399
  263.  
  264. #define GEN_FUNC    300
  265. #define GEN_FUNC_OFFSET    300
  266. #define IS_GEN_FUNCTION(Token)        (Token >= 300 && Token < 400)
  267.  
  268. #define IS_FUNCTION(Token)              (Token >= 100 && Token < 400)
  269. #define IS_NO_PARAM_FUNC(Token)        (Token == EXIT || Token == SYSTEM || \
  270.                      Token == VARLIST)
  271.  
  272. #define    PLUS        400                           /* Operators. */
  273. #define    MINUS        401
  274. #define    MULT        402
  275. #define    DIV        403
  276. #define    POWER        404
  277. #define    UNARMINUS   405
  278. #define EQUAL        406
  279. #define COMMA        407
  280. #define COLON        408
  281. #define SEMICOLON   409
  282.  
  283. #define    OPENPARA    430                         /* Paranthesis. */
  284. #define    CLOSPARA    431
  285.  
  286. #define    NUMBER        450                        /* Numeric Data. */
  287. #define    PARAMETER   451                 /* Point on new/old object. */
  288. #define STRING        452         /* Sequence of characters within double quotes. */
  289.  
  290. #define TOKENSTART  490
  291. #define TOKENEND    491
  292.  
  293. #define OPERATORS   400
  294. #define OPERATORS_OFFSET    400
  295.  
  296. /*****************************************************************************
  297. *   The local function (static) prototypes:                     *
  298. *   Note that if DEBUG is defined for the preprocessor, few more function    *
  299. * become available:                                 *
  300. *   Also note that some of the routines are defined globals as both the      *
  301. * InptPrsr.c and InptEval.c modules needs them.                     *
  302. *****************************************************************************/
  303. /* Main parser routine (operator preceedence): Input stream to bin-tree. */
  304. ParseTree *MyExprMalloc(void);
  305. void MyExprFree(ParseTree *Ptr);
  306. void UpdateCharError(char *StrMsg, int Token);
  307. void AliasEdit(char *Name, char *Value);
  308. void AliasExpand(char *Line);
  309. void FileInclude(char *FileName);
  310. IritExprType InptPrsrTypeCheck(ParseTree *Root, int Level);   /* Type check. */
  311. ParseTree *InptPrsrEvalTree(ParseTree *Root, int Level);   /* Evaluate tree. */
  312. void InptPrsrFreeTree(ParseTree *Root);               /* Free all tree. */
  313. void InptPrsrPrintTree(ParseTree *Root, char *str);          /* print it... */
  314. ParseTree *InptPrsrCopyTree(ParseTree *Root);             /* Copy it. */
  315.  
  316. #endif    /* INPT_PRSR_LH */
  317.